package com.project.server.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.server.model.Restaurant;
import com.project.server.common.Result;
import com.project.server.service.RestaurantService;
import com.project.server.vo.RestaurantVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "餐厅管理")
@RestController
@RequestMapping("/api/restaurant")
@RequiredArgsConstructor
public class RestaurantController {

    private final RestaurantService restaurantService;

    @Operation(summary = "分页查询餐厅列表")
    @GetMapping("/page")
    public Result<Page<Restaurant>> page(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String name) {
        return Result.success(restaurantService.page(pageNum, pageSize, name));
    }

    @Operation(summary = "获取餐厅详情")
    @GetMapping("/{id}")
    public Result<RestaurantVO> getDetail(@PathVariable Long id) {
        return Result.success(restaurantService.getDetail(id));
    }

    @Operation(summary = "新增餐厅")
    @PostMapping
    public Result<Void> save(@RequestBody @Validated Restaurant restaurant) {
        restaurantService.save(restaurant);
        return Result.success();
    }

    @Operation(summary = "更新餐厅")
    @PutMapping
    public Result<Void> update(@RequestBody @Validated Restaurant restaurant) {
        restaurantService.update(restaurant);
        return Result.success();
    }

    @Operation(summary = "删除餐厅")
    @DeleteMapping("/{id}")
    public Result<Void> remove(@PathVariable Long id) {
        restaurantService.removeById(id);
        return Result.success();
    }

    @Operation(summary = "更新餐厅状态")
    @PutMapping("/status/{id}/{status}")
    public Result<Void> updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        restaurantService.updateStatus(id, status);
        return Result.success();
    }


    @Operation(summary = "查询全部餐厅")
    @GetMapping("/list/all")
    public Result<List<Restaurant>> queryAll() {
        return Result.success(restaurantService.queryAll());
    }







}
